package com.kuang.demo.service.wx;

import com.github.pagehelper.PageHelper;
import com.kuang.demo.bean.wx.TopicDetail;
import com.kuang.demo.bean.wx.TopicList;
import com.kuang.demo.bean.wx.TopicRelated;
import com.kuang.demo.mapper.wx.WXTopicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WXTopicServiceImpl implements WXTopicService {
    @Autowired
    WXTopicMapper wxTopicMapper;

    @Override
    public TopicList getTopicList(int page, int size) {
        PageHelper.startPage(page, size);
        TopicList topicList = new TopicList();
        int i = wxTopicMapper.selectCountTopicList();
        topicList.setCount(i);
        List<TopicList.DataBean> dataBeans;
        dataBeans = wxTopicMapper.selectAllTopicList();
        topicList.setData(dataBeans);
        return topicList;
    }

    @Override
    public TopicDetail getTopicDetail(int id) {
        TopicDetail.DataBean.TopicBean topicBean ;
        TopicDetail.DataBean dataBean = new TopicDetail.DataBean();
        topicBean = wxTopicMapper.selectTopicDetailById(id);
        dataBean.setTopic(topicBean);
        List<Integer> goods=new ArrayList<>();
        dataBean.setGoods(goods);
        TopicDetail topicDetail = new TopicDetail();
        topicDetail.setData(dataBean);

        return topicDetail;
    }

    @Override
    public TopicRelated getTopicRelated(int id) {
        List<TopicRelated.DataBean> dataBeans;
        dataBeans=wxTopicMapper.selectAllTopicButId(id);
        TopicRelated topicRelated = new TopicRelated();
        topicRelated.setData(dataBeans);
        return topicRelated;
    }
}
